package org.jeecg.modules.common.utils;

import org.jeecg.modules.common.IDeviceRunningStatusChange;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Classname CamelliaDeviceStatusChanger
 * @Description TODO
 * @Date 2023/5/29 19:24
 * @Created by 10835
 */
@Component
public class CamelliaDeviceStatusChanger {
    @Resource
    private IDeviceRunningStatusChange deviceRunningStatusChange;
    private AtomicInteger camelliaDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger refrigeratorDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger airCompressorDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger hotWaterPumpDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger solventPumpDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger vacuumPumpDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger compressorDeviceAtomic = new AtomicInteger(0);
    private AtomicInteger waterTankDeviceAtomic = new AtomicInteger(0);

    public synchronized void camelliaDeviceStatus(int camelliaDevice, int refrigerator, int airCompressor, int hotWaterPump,
                                     int solventPump, int vacuumPump, int compressorDevice, int waterTank) {

        if (camelliaDeviceAtomic.get() != camelliaDevice) {
            camelliaDeviceAtomic.set(camelliaDevice);
            if (camelliaDevice == 1) {
                deviceRunningStatusChange.open("亚临界设备");
            }else {
                deviceRunningStatusChange.close("亚临界设备");
            }
        }
        if (refrigeratorDeviceAtomic.get() != refrigerator) {
            refrigeratorDeviceAtomic.set(refrigerator);
            if (refrigerator == 1) {
                deviceRunningStatusChange.open("制冷机");
            } else {
                deviceRunningStatusChange.close("制冷机");
            }
        }
        if (airCompressorDeviceAtomic.get() != airCompressor) {
            airCompressorDeviceAtomic.set(airCompressor);
            if (airCompressor == 1) {
                deviceRunningStatusChange.open("空压机");
            } else {
                deviceRunningStatusChange.close("空压机");
            }
        }
        if (hotWaterPumpDeviceAtomic.get() != hotWaterPump) {
            hotWaterPumpDeviceAtomic.set(hotWaterPump);
            if (hotWaterPump == 1) {
                deviceRunningStatusChange.open("热水泵");
            } else {
                deviceRunningStatusChange.close("热水泵");
            }
        }
        if (solventPumpDeviceAtomic.get() != solventPump) {
            solventPumpDeviceAtomic.set(solventPump);
            if (solventPump == 1) {
                deviceRunningStatusChange.open("溶剂泵");
            } else {
                deviceRunningStatusChange.close("溶剂泵");
            }
        }
        if (vacuumPumpDeviceAtomic.get() != vacuumPump) {
            vacuumPumpDeviceAtomic.set(vacuumPump);
            if (vacuumPump == 1) {
                deviceRunningStatusChange.open("真空泵");
            } else {
                deviceRunningStatusChange.close("真空泵");
            }
        }
        if (compressorDeviceAtomic.get() != compressorDevice) {
            compressorDeviceAtomic.set(compressorDevice);
            if (compressorDevice == 1) {
                deviceRunningStatusChange.open("压缩机");
            } else {
                deviceRunningStatusChange.close("压缩机");
            }
        }
        if (waterTankDeviceAtomic.get() != waterTank) {
            waterTankDeviceAtomic.set(waterTank);
            if (waterTank == 1) {
                deviceRunningStatusChange.open("热水箱加热器");
            } else {
                deviceRunningStatusChange.close("热水箱加热器");
            }
        }
    }
}
